﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bank
{
    class Bank
    {
        private List<Account> accounts = new List<Account>();

        public void AddAccount(Account account)
        {
            accounts.Add(account);
        }

        public Account this[int accountNumber]
        {
            get
            {
                return accounts.Find(acc => acc.AccountNumber == accountNumber);
            }
        }
    }

    class Account
    {
        private static int nextAccountNumber = 1000;
        public int AccountNumber { get; private set; }
        public string Owner { get; private set; }
        protected decimal Balance { get; set; }

        public Account(string owner, decimal initialBalance)
        {
            AccountNumber = nextAccountNumber++;
            Owner = owner;
            Balance = initialBalance;
        }

        public virtual void Deposit(decimal amount)
        {
            if (amount > 0)
            {
                Balance += amount;
                Console.WriteLine($"存款成功，当前余额：{Balance:C}");
            }
            else
            {
                Console.WriteLine("存款金额必须大于0！");
            }
        }

        public virtual bool Withdraw(decimal amount)
        {
            if (amount > 0 && Balance >= amount)
            {
                Balance -= amount;
                Console.WriteLine($"取款成功，当前余额：{Balance:C}");
                return true;
            }
            Console.WriteLine("取款失败，余额不足！");
            return false;
        }

        public void DisplayBalance()
        {
            Console.WriteLine($"{Owner} 的账户余额：{Balance:C}");
        }
    }

    class CreditAccount : Account
    {
        public decimal CreditLimit { get; private set; }

        public CreditAccount(string owner, decimal initialBalance, decimal creditLimit)
            : base(owner, initialBalance)
        {
            CreditLimit = creditLimit;
        }

        public override bool Withdraw(decimal amount)
        {
            if (amount > 0 && Balance + CreditLimit >= amount)
            {
                Balance -= amount;
                Console.WriteLine($"取款成功（信用额度），当前余额：{Balance:C}");
                return true;
            }
            Console.WriteLine("取款失败，超过信用额度！");
            return false;
        }

        public void DisplayCreditLimit()
        {
            Console.WriteLine($"{Owner} 的信用额度为：{CreditLimit:C}");
        }
    }

    class ATM
    {
        private Bank bank;

        public ATM(Bank bank)
        {
            this.bank = bank;
        }

        }
    }

